package com.ptmall.app.ui.adapter;

import android.app.Activity;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.ptmall.app.R;
import com.ptmall.app.bean.ShareCouponBean;
import java.util.ArrayList;
import java.util.List;


/**
 * Created by zjh on 2016/9/23.
 * 新品推荐
 */
public class ShareCouponAdapter extends RecyclerView.Adapter<ShareCouponAdapter.ViewHolder> {

    private Activity mActivity;
    private List<ShareCouponBean> mData = new ArrayList();

    public void setClickInterface(ClickInterface clickInterface){
        this.clickInterface = clickInterface;
    }

    public ClickInterface clickInterface;

    public ShareCouponAdapter(Activity mActivity) {
        this.mActivity = mActivity;
    }

    public void bind(List<ShareCouponBean> mData) {
        this.mData = mData;
        notifyDataSetChanged();
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_sharecoupon, parent, false);
        return new ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(final ViewHolder holder, int position) {
        holder.mon.setText(mData.get(position).money+"元");
        if(mData.get(position).type == 1){
            holder.quantype.setText("通用券");
        }else {
            holder.quantype.setText("指定券");
        }
        holder.lingqu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                clickInterface.addq(position,mData.get(position).quanId+"");
            }
        });
    }

    @Override
    public int getItemCount() {
        return mData.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder {

        TextView mon,quantype;
        RelativeLayout lingqu;

        public ViewHolder(View view) {
            super(view);
            quantype = (TextView) view.findViewById(R.id.quantype);
            mon = (TextView) view.findViewById(R.id.mon);
            lingqu = (RelativeLayout) view.findViewById(R.id.lingqu);
        }
    }



    public interface ClickInterface{
        void addq(int position,String id);
    }

}
